<template>
  <div>
    <van-address-edit
      :area-list="areaList"
      show-delete
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
      @confirn='submit'
    />
  </div>
</template>

<script>
import { ref } from "vue";
import { Toast } from "vant";
import { areaList } from '@vant/area-data';

export default {
  setup() {
    const searchResult = ref([]);

    const onSave = () => Toast('save');
    const onDelete = () => Toast('delete');
    const onChangeDetail = (val) => {
      if (val) {
        searchResult.value = [
          {
            name: '故宫',
            address: '北京市皇城区',
          },
        ];
      } else {
        searchResult.value = [
          {
            name: '紫禁城',
            address: '北京市',
          }
        ];
      }
    };

    return {
      
      onSave,
      onDelete,
      areaList,
      searchResult,
      onChangeDetail,
    };
  },
  methods:{
    onSave(){
      this.axios.post('/index/address').then((result) => {
          console.log('添加成功', 200)
          this.$router.push('/dizhi')
      }).catch((err) => {
         console.log('添加失败', 400)
      });
    }
  },
};
</script>

<style scoped >
* {
  margin: 0;
}
</style>
